package zoolisten;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List;

public class Content {
    public static void main(String[] args) {
//        Programs arguments 3 2 使用空格来分割
        System.out.println("hi 0 "+args[0]);
        System.out.println("hi 1 "+args[1]);
    }
    List<String> a =Arrays.asList(
            "日照香炉生紫烟","遥看瀑布挂前川",
            "飞流直下三千尺","疑是银河落九天" );
    List<String> b =Arrays.asList("朱雀桥边野草花","乌衣巷口夕阳斜",
            "旧时王谢堂前燕","飞入寻常百姓家");
    List<String> c = Arrays.asList("少小离家老大回","乡音无改鬓毛催",
            "儿童相见不相识","笑问客从何处来");
    private FileChannel fileChannel;

    public Content(Path file) throws IOException {
        this.fileChannel = FileChannel.open(file, StandardOpenOption.APPEND);
    }

    public void writeInto(String t) throws IOException, InterruptedException {

        switch (t){
            case "a":
                a.forEach(i->{
                    try {
                        fileChannel.write(ByteBuffer.wrap((i+"\n").getBytes()));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
                fileChannel.write(ByteBuffer.wrap("-----------\n".getBytes()));
                break;
            case "b":
                b.forEach(i->{
                    try {
                        fileChannel.write(ByteBuffer.wrap((i+"\n").getBytes()));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
                fileChannel.write(ByteBuffer.wrap("===========\n".getBytes()));
                break;
            case "c":
                c.forEach(i->{
                    try {
                        fileChannel.write(ByteBuffer.wrap((i+"\n").getBytes()));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
                fileChannel.write(ByteBuffer.wrap("*********\n".getBytes()));
                break;
        }
        Thread.sleep(3000);
        fileChannel.close();

    }
}
